package cn.dkdoo.utils.config;

import cn.dkdoo.utils.config.transactionInfo.TransactionInfoAbstract;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 验证当前事物是否开启
 */
@Aspect
@Component
public class DkdCheckTraOpenAspect {
    private static final Logger logger = LoggerFactory.getLogger(DkdCheckTraOpenAspect.class);

    @Pointcut(value = "@annotation(cn.dkdoo.utils.annotation.DkdCheckTraOpen)")
    public void point() {
    }

    @Around("point()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        if (TransactionInfoAbstract.checkIsClose()) {
            logger.warn("方法：【{}】事物已关闭!", joinPoint.toString());
            return null;
        }
        return joinPoint.proceed();
    }


}
